package com.lvy.hczn.front.web.controller.system;

import java.util.List;

import com.lvy.hczn.front.common.core.domain.entity.SysUser;
import com.lvy.hczn.front.system.domain.system.SysUserBase;
import com.lvy.hczn.front.system.service.ISysUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.lvy.hczn.front.common.annotation.Log;
import com.lvy.hczn.front.common.enums.BusinessType;
import com.lvy.hczn.front.system.service.ISysUserBaseService;
import com.lvy.hczn.front.common.core.controller.BaseController;
import com.lvy.hczn.front.common.core.domain.AjaxResult;
import com.lvy.hczn.front.common.utils.poi.ExcelUtil;
import com.lvy.hczn.front.common.core.page.TableDataInfo;

/**
 * 用户基本信息Controller
 *
 * @author ruoyi
 * @date 2023-11-24
 */
@Controller
@RequestMapping("/system/base")
public class SysUserBaseController extends BaseController {
    private String prefix = "system/user/base";

    @Autowired
    private ISysUserBaseService sysUserBaseService;

    @Autowired
    private ISysUserService sysUserService;

    @RequiresPermissions("system:base:view")
    @GetMapping()
    public String base() {
        return prefix + "/base";
    }

    /**
     * 查询用户基本信息列表
     */
    @RequiresPermissions("system:base:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysUserBase sysUserBase) {
        startPage();
        List<SysUserBase> list = sysUserBaseService.selectSysUserBaseList(sysUserBase);
        return getDataTable(list);
    }

    /**
     * 导出用户基本信息列表
     */
    @RequiresPermissions("system:base:export")
    @Log(title = "用户基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysUserBase sysUserBase) {
        List<SysUserBase> list = sysUserBaseService.selectSysUserBaseList(sysUserBase);
        ExcelUtil<SysUserBase> util = new ExcelUtil<SysUserBase>(SysUserBase.class);
        return util.exportExcel(list, "用户基本信息数据");
    }

    /**
     * 新增用户基本信息
     */
    @GetMapping("/add")
    public String add(ModelMap mmap) {
        List<SysUser> list = sysUserService.selectUserList(new SysUser());
        mmap.put("list", list);
        return prefix + "/add";
    }

    /**
     * 新增保存用户基本信息
     */
    @RequiresPermissions("system:base:add")
    @Log(title = "用户基本信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysUserBase sysUserBase) {
        return toAjax(sysUserBaseService.insertSysUserBase(sysUserBase));
    }

    /**
     * 修改用户基本信息
     */
    @RequiresPermissions("system:base:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        SysUserBase sysUserBase = sysUserBaseService.selectSysUserBaseById(id);
        mmap.put("sysUserBase", sysUserBase);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户基本信息
     */
    @RequiresPermissions("system:base:edit")
    @Log(title = "用户基本信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysUserBase sysUserBase) {
        return toAjax(sysUserBaseService.updateSysUserBase(sysUserBase));
    }

    /**
     * 删除用户基本信息
     */
    @RequiresPermissions("system:base:remove")
    @Log(title = "用户基本信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(sysUserBaseService.deleteSysUserBaseByIds(ids));
    }
}
